<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多选</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: skyblue;
        }
        .inbox {
            width: 300px;
            background-color: #fff;
            margin: 50px auto;
        }
        .inbox .item {
            display: flex;
            align-items: center;
            border: 2px solid yellow;
            /* justify-content: center; */
        }

    </style>
</head>
<body>
    <div class="inbox">
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>Check one item.</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.1</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.2</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.3</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.4</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.</p>
        </div>
        <div class="item">
            <input type="checkbox">
            <p>This is an inbox layout.</p>
        </div>
    </div>

    <script>
        const checkboxs = document.querySelectorAll('.inbox input[type=checkbox]')
        
        let startChecked;
        function handleCheck(e){
            if(e.shiftKey && this.checked){ //确定结束的边界
                let isBetween  = false
                checkboxs.forEach(checkbox => {
                    if(checkbox === startChecked || checkbox === this) {
                        isBetween = !isBetween
                    }
                    if(isBetween) {
                        checkbox.checked = true
                    }
                })
            }
            startChecked = this //确定开始的边界
        }

        checkboxs.forEach( checkbox => {
            checkbox.addEventListener('click',handleCheck)
        })
    </script>
</body>
</html>